<template>
  <div class="app-container">
    <!-- 查询区域 -->
    <el-form :model="queryParams" :ref="queryFormRef" inline v-show="showSearch" label-width="auto" @keyup.enter.native="handleQuery">
        <el-form-item label="用户" prop="userId">
          <el-input v-model="queryParams.userId" placeholder="用户" clearable />
        </el-form-item>
        <el-form-item label="商品" prop="prodId">
          <el-input v-model="queryParams.prodId" placeholder="商品" clearable />
        </el-form-item>
        <el-form-item label="浏览时间" prop="createTimeBegin">
          <el-date-picker clearable v-model="queryParams.createTimeBegin" value-format="yyyy-MM-dd" type="date" placeholder="浏览时间">
          </el-date-picker>-
        </el-form-item>
        <el-form-item label="浏览时间"prop="createTimeEnd">
          <el-date-picker clearable v-model="queryParams.createTimeEnd" value-format="yyyy-MM-dd" type="date" placehodelr="浏览时间">
          </el-date-picker>
        </el-form-item>
        <el-form-item label-width="0px">
          <el-button type="primary" icon="el-icon-search" @click="handleQuery">搜索</el-button>
          <el-button icon="el-icon-refresh" @click="resetQuery">重置</el-button>
        </el-form-item>
    </el-form>
    <!-- 查询区域-END -->

    <!-- 操作按钮区域 -->
    <div class="tool-bar-btn">
      <el-button type="success" icon="el-icon-tickets" :disabled="single" @click="handleDetail" v-hasPerms="['mall:userProdBrowse:detail']">详情</el-button>
      <el-button type="danger" icon="el-icon-delete" :disabled="multiple" @click="handleDelete" v-hasPerms="['mall:userProdBrowse:remove']">删除</el-button>
      <right-toolbar :showSearch.sync="showSearch" @queryTable="getList"></right-toolbar>
    </div>

    <!-- 表格区域 -->
    <selected-info :count="selectedRows.length" :onClearSelected="onClearSelected" />
    <el-table :ref="dataTableRef" v-loading="loading" :data="dataList" stripe border @selection-change="onSelectChange"
          :default-sort = "defaultSort" @sort-change="onSortChange" :row-key="rowKey">
      <el-table-column type="selection" width="55" align="center" fixed="left"/>
      <el-table-column label="编号" align="center" prop="id" sortable="custom" width="80"/>
      <el-table-column label="商铺" align="center" prop="shopId"  width="200" />
      <el-table-column label="用户" align="center" prop="userId"  width="200" />
      <el-table-column label="商品图片" align="center" prop="prodPic"  width="150" />
      <el-table-column label="商品名称" align="center" prop="prodName"  />
      <el-table-column label="浏览时间" align="center" prop="createTime"  width="160" />
      <el-table-column label="操作" align="center" fixed="right" class-name="small-padding fixed-width" width="200">
        <template slot-scope="{row}">
          <el-button type="text" icon="el-icon-tickets" @click="handleDetail(row)" v-hasPerms="['mall:userProdBrowse:detail']">详情</el-button>
          <el-button type="text" icon="el-icon-delete" @click="handleDelete(row)" v-hasPerms="['mall:userProdBrowse:remove']">删除</el-button>
        </template>
      </el-table-column>
    </el-table>

    <pagination v-show="!loading" :total="total" :page.sync="queryParams.pageNum" :limit.sync="queryParams.pageSize"  @pagination="getList" />

    <!-- 添加或修改对话框 -->
    <EditUserProdBrowse ref="formDialog" @ok="getList" />

  </div>
</template>

<script>
import {httpGet, httpDel} from '@/api';
import { IndexListMixin } from '@/components/mixins/IndexListMixin';
import EditUserProdBrowse from './edit';

export default {
  name: "UserProdBrowse",
  mixins:[IndexListMixin],
  components: {
    EditUserProdBrowse,
  },
  data() {
    return {
      // 查询参数
      queryParams: {
        keywords: null,
        shopId: null,
        userId: null,
        prodId: null,
        createTime: null,
        pageNum: 1,
        pageSize: 10
      },
      url: {
        base: '/mall/userProdBrowse/',
      	list: '/mall/userProdBrowse/list'
      }
    };
  },
  created() {
    this.getList();
  },
  mounted(){
  },
  methods: {
    getList() {
      this.loadData(this.url.list);
    },

    /** 查看详情按钮操作 */
    handleDetail(row) {
      const id = row.id || this.selectedRowKeys
      this.$refs.formDialog.toDetail("查看会员商品足迹详情", httpGet(this.url.base + id));
    },

    /** 删除按钮操作 */
    handleDelete(row) {
      const ids = row.id || this.selectedRowKeys
      this.deleteData(this.url.base, ids);
    },

  }
};
</script>
